package kr.hkit.powerjava.chapter22.work;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.StringTokenizer;

import javax.swing.JOptionPane;

public class TestMain {
	public static void main(String[] args) {
		ArrayList<Department> deptList = new ArrayList<>();
		DepartmentDAO deptDao = new DepartmentDAO(deptList);
		
		deptDao.addItem(new Department(1, "컴공", 4));
		deptDao.prnList();
		
	}
	/*	ArrayList<Student> stdList = new ArrayList<>();
		initList(stdList);
		StudentManager sm = new StudentManager(stdList);
		
		int res = 0;

		do {
			System.out.println("메뉴를 선택하세요");
			try{
				res = Integer.parseInt(JOptionPane.showInputDialog("1.추가 2.검색 3.수정 4.삭제 5.리스트 6.종료"));
			} catch(NumberFormatException e) {
				res = 6;
			}
			
			System.out.println("입력한 값은 "+res);
			switch(res) {
				case 1: sm.addItem(inputStudentInfo(true));
						prnList(stdList);
					break;
				case 2:	System.out.println(sm.serachItem(inputStudentInfo(false)));
					break;
				case 3: sm.updateItem(inputStudentInfo(false));
					break;
				case 4: sm.delItem(sm.serachItem(inputStudentInfo(false)));
					break;
				case 5: prnList(stdList);
					break;
				default:
						break;
			}
		}while(res < 6);
			
		ArrayList<Student> stdList = new ArrayList<>();
		initList(stdList);
		
		
		StudentManager sm = new StudentManager(stdList);
		sm.prnList();
		
		Student std = new Student(stdList.size()+1, "제시카", 60, 85, 55);
		sm.addStudent(std);
		sm.prnList();
		
		sm.delStudent(std);
		sm.prnList();
		
	
		Student std = new Student(2, "이민정");
		System.out.println(stdList.lastIndexOf(std)+"의 위치에 존재 "+stdList.contains(std));
	
		//총점순 정렬
		Collections.sort(stdList);
		prnHeader();
		prnList(stdList);
		
		//수학점수별 정렬
		Comparator<Student> comp = new Comparator<Student>() {

			@Override
			public int compare(Student o1, Student o2) {
				return o1.getMathScore() - o2.getMathScore();
			}
			
		};
		Collections.sort(stdList, comp);
		prnHeader();
		prnList(stdList);
	}
	private static Student inputStudent(ArrayList<Student> stdList) {
		int stdNum = stdList.size()+1;
		String stdName = JOptionPane.showInputDialog("이름을 입력하세요");
		int korSocre = Integer.parseInt(JOptionPane.showInputDialog("국어 점수를 입력하세요"));
		int engSocre = Integer.parseInt(JOptionPane.showInputDialog("영어 점수를 입력하세요"));
		int mathSocre = Integer.parseInt(JOptionPane.showInputDialog("수학 점수를 입력하세요"));
		
		return new Student(stdNum, stdName, korSocre, engSocre, mathSocre);
	}*/
	
	private static Student inputStudentInfo(boolean gubun) {
		if(gubun) {
			String std = JOptionPane.showInputDialog("학생정보 성명 국어 영어 수학");
			StringTokenizer st= new StringTokenizer(std);
			int stdNum = Integer.parseInt(st.nextToken());
			String stdName = st.nextToken();
			int kor = Integer.parseInt(st.nextToken());
			int eng = Integer.parseInt(st.nextToken());
			int math = Integer.parseInt(st.nextToken());
			
			return new Student(stdNum, stdName, kor, eng, math);
		} else {
			String std = JOptionPane.showInputDialog("학생번호 성명");
			StringTokenizer st= new StringTokenizer(std);
			int stdNum = Integer.parseInt(st.nextToken());
			String stdName = st.nextToken();
			
			return new Student(stdNum, stdName);
		}
	}
	
	private static void prnList(ArrayList<Student> stdList) {
		for(Student std : stdList) {
			System.out.println(std);
		}
	}
	
	private static void initList(ArrayList<Student> stdList) {
		stdList.add(new Student(1,"김태희",87,87,87));
		stdList.add(new Student(2,"이민정",90,60,70));
		stdList.add(new Student(3,"이소은",70,70,55));
		stdList.add(new Student(4,"최석열",60,80,100));
		stdList.add(new Student(5,"오은경",70,85,90));
//		stdList.add(new Student)
		
	}
}
